package tmp

import scala.language.dynamics

//by  http://unmi.cc/scala-2-10-0-new-feature-dynamic/
class Person extends Dynamic {
  def selectDynamic(method: String) {
    println(s"selectDynamic->$method called\n")
  }
  def applyDynamic(method: String)(args: Any*) {
    println(s"applyDynamic->$method called, args: $args\n")
  }
  def updateDynamic(method: String)(args: Any) {
    println(s"updateDynamic->$method called, args: $args\n")
  }
  def applyDynamicNamed(method: String)(args: (String, Any)*) {
    println(s"applyDynamicNamed->$method called, args: $args")
    for ((key, value) <- args) {
      println(s"key: $key, value: $value")
    }
  }
}

object DynamicDemoApp extends App {
  val p = new Person
  p.sayHello //calll selectDynamic
  p.config("Hello", "Unmi") //call applyDynamic
  p.products = ("iPhone", "Nexus") //call updateDynamic
  p.showInfo(screenName = "Unmi", email = "fantasia@sina.com") //call applyDynamicNamed

}